﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using System.ComponentModel;
using System.Windows.Navigation;
using System.Diagnostics;

namespace client
{
    public partial class SearchServicePage : PhoneApplicationPage
    {

        SearchService search;


        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            //RestaurantList.SelectedItem = null;
            //RestaurantList.SelectedIndex = -1;
           
        }

        public SearchServicePage()
        {
            InitializeComponent();
            search = new SearchService();
            DataContext = search;
            RestaurantList.ItemsSource = search.RestaurantList;
        }

        private void MenuClick(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/Menu.xaml", UriKind.Relative));
        }

        private void RestaurantClick(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/RestaurantPage.xaml", UriKind.Relative));
        }

        private void SearchClick(object sender, RoutedEventArgs e)
        {
            search.getService(string.Format("action=search&servicename={0}", textBox1.Text));

        }




        private void RestaurantList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
                int index = RestaurantList.SelectedIndex;
                Debug.WriteLine(index);
                if (index != -1)
                {
                RestaurantContent rc = (RestaurantContent)RestaurantList.SelectedItem;
                Debug.WriteLine("*****" + (rc == null));
                Debug.WriteLine(rc.Name);

                if (rc.Name != "RestaurantLocation")
                {
                    MessageBox.Show("Sorry!Service not supported!");

                }
                else
                {

                    Debug.WriteLine("-----" + index);
                    this.NavigationService.Navigate(new Uri("/RestaurantPage.xaml", UriKind.Relative));
                    MobileClient mClient=new MobileClient();
                    mClient.GPSService();
                }
            }




        }

        protected override void OnNavigatedFrom(NavigationEventArgs args)
        {
            // make sure no item is highlighted in the list of cities
            RestaurantList.SelectedIndex = -1;
            RestaurantList.SelectedItem = null;
        }



    }

}
